package com.wangp.mywrite.coding;

import java.util.Random;
import org.apache.http.util.Asserts;

/**
 * @author farling-wangp
 * @version 1.0
 * @date 2021/3/31 20:01
 */
public abstract class Sort {

    protected static int[] genRandomArr(int capacity) {
        int[] arr = new int[capacity];
        Random random = new Random();
        for (int i = 0; i < capacity; i++) {
            int num = random.nextInt(capacity);
            arr[i] = num;
        }
        return arr;
    }

    protected static void checkArrOrder(int[] arr) {
        for (int i = 0; i < arr.length - 1; i++) {
            Asserts.check(arr[i] <= arr[i + 1], "未排好序！");
        }
    }

    protected static void swap(int[] arr, int i, int j) {
        int tmp = arr[i];
        arr[i] = arr[j];
        arr[j] = tmp;
    }
}
